package pkg

import (
	"fmt"
	"github.com/smartwalle/alipay/v3"
	"strconv"
	"video-srv/basic/config"
)

func AliPay(orderSn string, amount int) (string, error) {
	appId := config.AppCfg.AliPay.AppId
	var privateKey = config.AppCfg.AliPay.PrivateKey
	var client, err = alipay.New(appId, privateKey, false)
	if err != nil {
		fmt.Println(err)
		return "", nil
	}
	var p = alipay.TradeWapPay{}
	p.NotifyURL = config.AppCfg.AliPay.NotifyURL
	p.ReturnURL = config.AppCfg.AliPay.ReturnURL
	p.Subject = "会员充值"
	p.OutTradeNo = orderSn
	p.TotalAmount = strconv.Itoa(amount)
	p.ProductCode = "QUICK_WAP_WAY"
	url, err := client.TradeWapPay(p)
	if err != nil {
		fmt.Println(err)
	}
	var payURL = url.String()
	return payURL, err
}
